package com.chalk.util;


import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chalk.common.util.RedisUtil;
import org.aspectj.weaver.ast.Var;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MyHttpUtils {

//    @Autowired
//    RedisUtil redisUtil;

    @Autowired
    private  RedisTemplate<Serializable, Object> redisTemplate;

    /**
     * 向指定 URL 发送POST方法的请求
     *
     * @param param 请求参数，请求参数应该是 name1=value1&name2=value2 的形式。
     * @return 所代表远程资源的响应结果
     */
    public  String sendPost(String param) {

//        System.out.println("username"+username);
//        System.out.println("----------------------redis"+redisTemplate);
        Object token=null;
        token = redisTemplate.opsForValue().get("token");
        System.out.println(token);
        if(token==null || "".equals(token)){
            getToken();
            token = redisTemplate.opsForValue().get("token");
            System.out.println(token);
        }
        Map<String,Object> map=new HashMap<>();
        map.put("image",param);
        JSON json=new JSONObject(map);
        String s = json.toJSONString();
        PrintWriter out = null;
        BufferedReader in = null;
        String result = "";
        try {
            URL realUrl = new URL("https://ocr.cn-north-4.myhuaweicloud.com/v1.0/ocr/license-plate");
            // 打开和URL之间的连接
            URLConnection conn = realUrl.openConnection();
            conn.setReadTimeout(10000);
            // 设置通用的请求属性
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("Content-Type", "application/json;charset=utf8");
            conn.setRequestProperty("X-Auth-Token", (String) token);
            conn.setRequestProperty("connection", "Keep-Alive");
            //MIIaTQYJKoZIhvcNAQcCoIIaPjCCGjoCAQExDTALBglghkgBZQMEAgEwghhfBgkqhkiG9w0BBwGgghhQBIIYTHsidG9rZW4iOnsiZXhwaXJlc19hdCI6I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VDLQwVRnFVBWMpGEi8SgW5dTADYGIcYooWYePTi89yC+7BKkTCNSQTGiSmiRaXPDh4kjEhtBkOERutY1K8C+Y=
            conn.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 发送POST请求必须设置如下两行
            conn.setDoOutput(true);
            conn.setDoInput(true);
            // 获取URLConnection对象对应的输出流
            out = new PrintWriter(conn.getOutputStream());
            // 发送请求参数
            out.print(s);
            // flush输出流的缓冲
            out.flush();
            // 定义BufferedReader输入流来读取URL的响应
            in = new BufferedReader(
                    new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (IOException e) {
            System.out.println("发送 POST 请求出现异常！" + e);
            e.printStackTrace();
            return result;
        }
        // 使用finally块来关闭输出流、输入流
        finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return result;
    }




    @Value("${usernameH}")
    private  String username;
    @Value("${passwordH}")
    private  String password;
    @Value("${accountNumberH}")
    private  String accountNumber;
//    获取用户的token   post请求
    /**
     * 向指定 URL 发送POST方法的请求
     * @return 所代表远程资源的响应结果
     */
    public  void getToken() {

        String param="{ \n" +
                "    \"auth\": { \n" +
                "        \"identity\": { \n" +
                "            \"methods\": [ \n" +
                "                \"password\" \n" +
                "            ], \n" +
                "            \"password\": { \n" +
                "                \"user\": { \n" +
                "                    \"name\": \""+username+"\",\n" +
                "                    \"password\": \""+password+"\",\n" +
                "                    \"domain\": { \n" +
                "                        \"name\": \""+accountNumber+"\"\n" +
                "                    } \n" +
                "                } \n" +
                "            } \n" +
                "        }, \n" +
                "        \"scope\": { \n" +
                "            \"project\": { \n" +
                "                \"name\": \"cn-north-4\" ,\n" +
                "                \"id\": \"093fef15088025b22f7fc016eea60aaa\" \n" +
                "            } \n" +
                "        } \n" +
                "    } \n" +
                "}";
        PrintWriter out = null;
        BufferedReader in = null;
        String result = "";
        String token="";
        try {
            URL realUrl = new URL("https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens");
            // 打开和URL之间的连接
            URLConnection conn = realUrl.openConnection();
            conn.setReadTimeout(10000);
            // 设置通用的请求属性
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("Content-Type", "application/json;charset=utf8");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 发送POST请求必须设置如下两行
            conn.setDoOutput(true);
            conn.setDoInput(true);
            // 获取URLConnection对象对应的输出流
            out = new PrintWriter(conn.getOutputStream());
            // 发送请求参数
            out.print(param);
            // flush输出流的缓冲
            out.flush();
            Map<String, List<String>> map = conn.getHeaderFields();
            for (Map.Entry<String, List<String>> entry : map.entrySet()) {
                System.out.println("Key : " + entry.getKey() +
                        " ,Value : " + entry.getValue());
            }
            List<String> tokens = map.get("X-Subject-Token");
            token = tokens.get(0);
            // 定义BufferedReader输入流来读取URL的响应
//            in = new BufferedReader(
//                    new InputStreamReader(conn.getInputStream()));
//            String line;
//            while ((line = in.readLine()) != null) {
//                result += line;
//            }
        } catch (Exception e) {
            System.out.println("发送 POST 请求出现异常！" + e);
            e.printStackTrace();
        }
        // 使用finally块来关闭输出流、输入流
        finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        redisTemplate.opsForValue().set("token",token,1L, TimeUnit.DAYS);
    }
}
